


#include "compile_run.hpp"

#include "../common/httplib.h"

using namespace rs_compile_and_run;
using namespace httplib;

void porterr(std::string porc)
{
   std::cerr << "Usage" << "\n\r" << porc << "port";
    
}

int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        porterr(argv[0]);
        return 1;
    }

    Server svr;
    // svr.Get("/complier_and_run",[](const Request& req,Response &resp){
    //     resp.set_content("你好 httplib","text/plain;charset=utf-8");
    // });

    svr.Post("/complier_and_run",[](const Request& req,Response &resp){
        std::string out_json;
        std::string in_json = req.body;

        if(!in_json.empty())
        {
            CompileAndRun::Start(in_json,&out_json);
            resp.set_content(out_json,"application/json;charset=utf-8");
        }
        //resp.set_content(in_json,"application/json;charset=utf-8");
        
    });
    
    svr.listen("0.0.0.0",atoi(argv[1]));
    return 0;
}



